﻿@{
    Layout = null;
}
@using CNKI.TPI.Web.Search.Model;
@using CNKI.TPI.Web.Base
<script>
    function editFavCate(fid,cid)
    {
        $("#folderid").val(fid);
        ;
        //设置默认值
        $("input[name='favcate'][value=" + cid + "]").attr("checked", true);
        showcate();
    }
    function delFavCate(id)
    {
        var urlstr = "@Html.Raw(Url.Action("DelFolder", "UserCenter"))";
        var dataobj = { "id": id };
        confirmDialog('确定要删除吗?', function () {
            $.ajax({
                type: "GET",
                url: timestamp(urlstr),
                data: dataobj,
                success: function (msg) {
                    if (msg == "True") {
                        var urlstr = "@Html.Raw(Url.Action("FavFolder", "UserCenter"))";
                        ajaxLoad("initload", timestamp(urlstr)); //刷新列表页
                    }
                    else {
                        messageAlert("删除失败！");
                    }
                },
                error: function (e)
                { }
            })
        })
    }
    function dealdata()
    {

    }
    function showcate()
    {
        $.ajax({
            type: "GET",
            url: timestamp("@Html.Raw(Url.Action("GetFavList", "UserCenter"))"),
        beforeSend: function () { $("#loading").show(); },
        success: function (msg) {
            var obj = eval(msg);
            $(".ulfield").empty();
            if (obj != null && obj.length > 0) {
                for (var i = 0; i < obj.length; i++) {
                    var listr = " <li class=\"f-ct\" style=\"margin-left: 2em;\">  <label class=\"f-label block right\">" +
                   " <input type=\"radio\" name=\"favcate\" class=\"f-checkboxR\"  value='" + obj[i].FavoriteCategoryID + "' />" + obj[i].CategoryName + "</label></li>";
                    $(".ulfield").append(listr);
                }
                //默认第一个选中
                $('input:radio:first').attr('checked', 'checked');
            }
            $("#loading").hide();
        },
        error: function (e)
        { $("#loading").hide(); }

    })
        $(".talkDivBg").show();
        $(".floderform").show();
    }
    function hidecate() {
        $(".talkDivBg").hide();
        $(".floderform").hide();
    }
    function savecate()
    {
        var favcateid = $("input[name='favcate']:checked").val();
        if (favcateid == "")
        {
            messageAlert("请选择分类！");
        }
        var saveurl = "@Html.Raw(Url.Action("UpdateFolderCate", "UserCenter"))";
        $.ajax({
            type: "POST",
            data: { "cateid": favcateid, "floderid": $("#folderid").val() },
            url: saveurl,
            success: function (f) {
                if (f == "True") {
                    var urlstr = "@Html.Raw(Url.Action("FavFolder", "UserCenter"))";
                    ajaxLoad("initload", timestamp(urlstr)); //刷新列表页
                    messageAlert("操作成功！");
                }
                else {
                    messageAlert("操作失败！");
                }
                hidecate();
            },
            error: function (e)
            { hidecate(); }
        })
    }
    //全选
    function checkall(e) {
        if ($(e).attr("checked") == "checked") {
            $(".checkboxlist input[type='checkbox']").each(function () {
                $(this).attr("checked", "checked");
            })
        }
        else {
            $(".checkboxlist input[type='checkbox']").each(function () {
                $(this).removeAttr("checked", "checked");
            })
        }
    }
    $(".checkboxlist input[type='checkbox']").click(function () {
        //循环判断列表中的checkbox，如果全部选中则全选框呈勾选状态
        var m = 0;
        if ($(this).attr("checked") != "checked") {
            $("input.listheader").removeAttr("checked", "checked");
        }
        else {
            $(".checkboxlist input[type='checkbox']").each(function () {
                if ($(this).attr("checked") != "checked") {
                    m = 1;
                }
            })
            if (m == 1) {
                $("input.listheader").removeAttr("checked", "checked");
            }
            else {
                $("input.listheader").attr("checked", "checked");
            }
        }

    })
    //批量删除
    function bathDel() {
        var ckbs = $(".checkboxlist input[type='checkbox']:checked");
        if (ckbs.size() == 0) {
            messageAlert("请选择要删除的记录！");
            return;
        }
        var checkedstr = [];
        ckbs.each(function () {
            checkedstr.push($(this).val());
        })
        delFavCate(checkedstr.toString());
    }
</script>
<input type="hidden" id="folderid" />
        <a class="btn btn-submit btn-warn-f" style="margin-bottom: 10px" onclick="bathDel()">批量删除</a>
<table width="100%" cellspacing="0" cellpadding="0" border="0" class="table table-grey">
    <thead>
        <tr class="thead">
            <th class="tdnum"> <input type="checkbox" class="listheader" onclick="checkall(this)"></th>
            <th class="tl" style="width:30px"> 序号</th>
            <th class='tl' style="width:35%">篇名</th>
            <th class='tl' style="width:15%">数据库名称</th>
            <th class='tl' style="width:15%">收藏分类</th>
            <th class='tl' style="width:80px">收藏时间</th>
            <th style="width:90px">操作</th>
        </tr>
    </thead>
    <tbody>
        @{if (ViewBag.SearchList != null)
          {
              int sortno = ViewBag.PageSize * (ViewBag.PageNow - 1) + 1;
              foreach (System.Data.DataRow dr in ViewBag.SearchList.Rows)
              {

                  string str = "even";
                  if (sortno % 2 == 0)
                  {
                      str = "odd";
                  }
            <tr class='@str'>         
                <td style="word-break: normal;width:60px" class="checkboxlist"><input name="" type="checkbox" value="@dr["FavoriteFolderID"]" /> </td>
                <td> @sortno</td>
        
                   <td><a target="_blank" href="@dr["DetailUrL"]" title="@Html.Raw(dr["RecordTitle"].ToString())">@Html.Raw(ColumnAliasHelper.SubContent(dr["RecordTitle"].ToString(), 40))</a></td>
                <td>@dr["DBName"]</td>
                   <td>@dr["CategoryName"]</td>
                <td style="text-align: center">
                   @{ 
                       string datastr=((DateTime)dr["FavoriteDate"]).ToString("yyyy-MM-dd");
                       
                       }
                    @datastr
                </td>
                   <td class="tc">
                        <a href="javascript:void(0);"   onclick="javascript:editFavCate('@dr["FavoriteFolderID"]','@dr["FavoriteCategoryID"]')">修改分类</a>
                        <a  href="javascript:void(0);" onclick="delFavCate('@dr["FavoriteFolderID"]')">删除</a>
                    </td>

            </tr>
                  sortno = sortno + 1;
              }
          }

        }
    </tbody>
</table>

@*//分页*@
<div class="pagenav pagenav-02">
    @*上一页*@
    @if (ViewBag.TotalPage > 0)
    {
        if (ViewBag.PageNow != 1)
        {
            int thispage = ViewBag.PageNow - 1;
        <a href="javascript:void(0);" class="page-prev" onclick="searchPageNew('@thispage')" >上一页</a>
        }
        else
        {
        <a href="javascript:return false;" onclick="return false" class="page-prev disable">上一页</a>
        }
@*循环初始化页码*@
        foreach (string numpage in ViewBag.PageList)
        {
            if (numpage != "0")
            {
                int m = int.Parse(numpage);
                if (m == ViewBag.PageNow)
                {
        <a href="javascript:void(0);" class="active" onclick="searchPageNew('@numpage')">@numpage</a>
                    
                }
                else
                {
        <a href="javascript:void(0);" onclick="searchPageNew('@numpage')">@numpage</a>
                }

            }
            else
            {
        <i class="iconfont icon-dian2"></i>
            }

        }
@*下一页*@
        if (ViewBag.TotalPage > 0 && ViewBag.PageNow != ViewBag.TotalPage)
        {
            int nextpage = ViewBag.PageNow + 1;
        <a href="javascript:void(0);" class="page-next" onclick="searchPageNew('@nextpage')" >下一页</a>
        }
        else
        {
        <a href="javascript:return false;" onclick="return false" class="page-prev disable">下一页</a>
        }
    }
    @if (@ViewBag.Count == 0)
    {
        <label>暂无数据！</label>
        
    }
    else
    {
          
        <label>共 </label>
        <label>@ViewBag.Count </label>
        <label>条数据 </label>
    }
</div>

